#![no_main]
#![no_std]

use core::ops::Deref;

use md5_rs::Context;
use stm32f1::{self as _, stm32f103::{afio, bkp, pwr}};

pub mod gpio;
pub mod rcc;
pub mod dma;
pub mod uart;
pub mod tim;
pub mod flash;
pub mod adc;

pub mod utils;

pub use stm32f1::stm32f103::Interrupt;
pub use stm32f1::stm32f103::NVIC;
pub use stm32f1::stm32f103::interrupt;
pub struct BKP;

impl Deref for BKP {
    type Target = bkp::RegisterBlock;
    fn deref(&self) -> &Self::Target {
        unsafe { &*stm32f1::stm32f103::BKP::PTR }
    }
}

pub struct PWR;

impl Deref for PWR {
    type Target = pwr::RegisterBlock;
    fn deref(&self) -> &Self::Target {
        unsafe { &*stm32f1::stm32f103::PWR::PTR }
    }
}

pub struct AFIO;

impl Deref for AFIO {
    type Target = afio::RegisterBlock;
    fn deref(&self) -> &Self::Target {
        unsafe { &*stm32f1::stm32f103::AFIO::PTR }
    }
}

pub fn calc_md5(buf: &[u8]) -> [u8; 16] {
    let mut ctx = Context::new();
    ctx.read(buf);
    ctx.finish()
}

